package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.MenuDao;
import com.itheima.entity.PageResult;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = MenuService.class)
@Transactional
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuDao menuDao;
    @Override
    public PageResult findPage(Integer currentPage, Integer pageSize, String queryString) {

        PageHelper.startPage(currentPage,pageSize);

        Page<Menu> page=menuDao.findPage(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void add(Menu menu) {
           menuDao.add(menu);
    }

    @Override
    public void edit(Menu menu) {
           menuDao.edit(menu);
    }

    @Override
    public Menu findById(String id) {
        Menu menu=menuDao.findById(Integer.parseInt(id));
        return menu;
    }

    @Override
    public void delete(int id) {
        menuDao.delete(id);
    }

    @Override
    public List<Menu> findAll() {

            return menuDao.findAll();

    }
}
